const ipconfig = require('./ipconfig');
const express = require('express');
const path = require('path');
const app = express();
const bodyparser = require('body-parser');
const fs = require('fs');
const cors = require('cors');
app.use(cors());
app.use(bodyparser.urlencoded({
  extended:false
}));
app.use(bodyparser.json());
app.use(express.static(path.join(__dirname,'static')));
//websocket
const WebSocketServer = require('ws').Server;
const server = require('http').createServer();
const wss = new WebSocketServer({
  server:server,
  path:'/ws'
});
server.on('request',app);
const openws = require('./ws/index');
openws(wss);
server.listen(ipconfig.port, () => {
  console.log(`服务器启动成功!
    网络服务器地址：${'\033[96;49m'}http://${ipconfig.ip}:${ipconfig.port}${'\033[0m'}（不发布不生效）
    本地服务器地址：${'\033[96;49m'}http://localhost:${ipconfig.port}${'\033[0m'}`);
});

const punch = require('./router/train/punch');
app.use('/local-api/punch', punch);
const ceshi = require('./router/ceshi/ceshi');   // 在router文件夹自己创建一个空的文件夹，编写自己的接口，调用该接口
app.use('/ceshi', ceshi);// 使用该接口
